package com.jhws.business.car.service;

import com.jhws.business.car.bo.Discount;
import com.jhws.core.db.BaseDao;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class DiscountService {
    @Resource
    private BaseDao BaseDao;

    /**
     * 保存优惠信息
     *
     * @param discount 优惠信息
     */
    public void saveDiscount(Discount discount) {
        BaseDao.saveOrUpdate(discount);
    }

    /**
     * 查询优惠信息
     *
     * @param id 优惠信息ID
     */
    public Discount queryDiscountInfo(long id) {
        return BaseDao.get(Discount.class, id);
    }

    /**
     * 条件查询优惠信息列表
     *
     * @param where 条件
     */
    public List<Discount> queryDiscounts(String where) {
        return BaseDao.findList("from Discount " + where);
    }

    /**
     * 删除优惠信息
     *
     * @param discount 优惠信息ID
     */
    public void deleteDiscount(Discount discount) {
        BaseDao.delete(discount);
    }

    /**
     * 条件删除优惠信息
     *
     * @param where 条件
     */
    public void deleteDiscount(String where) throws Exception {
        String sql = "delete from car_discount " + where;
        BaseDao.executeBySql(sql);
    }
}
